Telegram Group & Telegram Channel
🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5707
Create:
Last Update:

🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cppproglib/5707

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.

How To Find Channels On Telegram?

There are multiple ways you can search for Telegram channels. One of the methods is really logical and you should all know it by now. We’re talking about using Telegram’s native search option. Make sure to download Telegram from the official website or update it to the latest version, using this link. Once you’ve installed Telegram, you can simply open the app and use the search bar. Tap on the magnifier icon and search for a channel that might interest you (e.g. Marvel comics). Even though this is the easiest method for searching Telegram channels, it isn’t the best one. This method is limited because it shows you only a couple of results per search.

Библиотека C C разработчика | cpp boost qt from ye


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA